local extension = Package("fengqi_forest")
extension.extensionName = "aaa_fengqi"

Fk:loadTranslationTable{
  ["fengqi_forest"] = "林",
}









local efengqi__godlvbu = General:new(extension, "efengqi__godlvbu", "god", 5,5)
Fk:loadTranslationTable{
  ["efengqi__godlvbu"] = "神吕布",
  ["#efengqi__godlvbu"] = "六臂修罗",
  ["designer:efengqi__godlvbu"] = "汤圆",
  ["cv:efengqi__godlvbu"] = "官方",
  ["illustrator:efengqi__godlvbu"] = "魔奇士",
}
local getAllCardNames = function(guhuo_type, true_name)
  local all_names = {}
  local basics = {}
  local normalTricks = {}
  local delayedTricks = {}
  local equips = {}
  for _, card in ipairs(Fk.cards) do
    if not table.contains(Fk:currentRoom().disabled_packs, card.package.name) and not card.is_derived then
      if card.type == Card.TypeBasic then
        table.insertIfNeed(basics, true_name and card.trueName or card.name)
      elseif card.type == Card.TypeTrick and card.sub_type ~= Card.SubtypeDelayedTrick then
        table.insertIfNeed(normalTricks, true_name and card.trueName or card.name)
      elseif card.type == Card.TypeTrick and card.sub_type == Card.SubtypeDelayedTrick then
        table.insertIfNeed(delayedTricks, true_name and card.trueName or card.name)
      elseif card.type == Card.TypeEquip then
        table.insertIfNeed(equips, true_name and card.trueName or card.name)
      end
    end
  end
  if guhuo_type:find("b") then
    table.insertTable(all_names, basics)
  end
  if guhuo_type:find("t") then
    table.insertTable(all_names, normalTricks)
  end
  if guhuo_type:find("d") then
    table.insertTable(all_names, delayedTricks)
  end
  if guhuo_type:find("e") then
    table.insertTable(all_names, equips)
  end
  return all_names
end
local halberd = {{"py_halberd", Card.Diamond, 12}}
local xiuluo = fk.CreateTriggerSkill{
  events = {fk.EventPhaseStart,fk.Damage,fk.Damaged},
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  name ="efengqi__xiuluo",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) and target == player then
      if event == fk.EventPhaseStart then
        local banner = player.room:getBanner("@$OutGameWeapons")or {}
        if not table.find(player:getCardIds('e'),function(cid) 
        return  Util.TranslateMapper(Fk:getCardById(cid).name)=="无双方天戟" end
      ) then
        return target.phase == Player.Start and #player:getAvailableEquipSlots(Card.SubtypeWeapon)>0
      end
      else
        local banner = player.room:getBanner("@$OutGameWeapons")or {}
        return #banner>0 and #player:getAvailableEquipSlots(Card.SubtypeWeapon)>0
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local banner = player.room:getBanner("@$OutGameWeapons")or {}
    if event == fk.EventPhaseStart then
      if not table.find(banner,function(cid) 
        local c = Fk:getCardById(cid)
        return Util.TranslateMapper(c.name) =="无双方天戟"
      end
      ) then
        local cid = U.prepareDeriveCards(room, {{"py_halberd", Card.Diamond, 12}}, "tyj__xiuluo_py_halberd")[1] or U.prepareDeriveCards(room, {{"rfenghou_halberd", Card.Diamond, 12}}, "tyj__xiuluo_py_halberd")[1]
        if U.canMoveCardIntoEquip(player, cid, true) then
          --room:setCardMark(Fk:getCardById(cid), MarkEnum.DestructOutEquip, 1)
        room:moveCardIntoEquip(player, cid, self.name, true, player)
        end
      else
        local cid = table.filter(banner,function(cid) 
          local c = Fk:getCardById(cid)
          return Util.TranslateMapper(c.name) == "无双方天戟"
        end
        )[1]
        if U.canMoveCardIntoEquip(player, cid, true) then
          --table.removeOne(banner,cid)
          --room:setBanner("@$OutGameWeapons", banner)
          room:setCardMark(Fk:getCardById(cid), MarkEnum.DestructOutEquip, 1)
          room:moveCardIntoEquip(player, cid, self.name, true, player)
          end
      end

    else
      local cids = table.filter(banner,function(cid) 
        return U.canMoveCardIntoEquip(player, cid, true)
      end
      )
      if #cids>0 then
        local cid = table.random(cids,1)[1]
        if cid then
          --table.removeOne(banner,cid)
          --room:setBanner("@$OutGameWeapons", banner)
          room:setCardMark(Fk:getCardById(cid), MarkEnum.DestructOutEquip, 1)
          room:moveCardIntoEquip(player, cid, self.name, true, player)
        end
      end
    end
  end,
  on_acquire = function (self, player, is_start)
    local room = player.room
    local x = player:getMark("xiuluo__extraslot")
    if x<5 then
      while x < 5 do
        x=x+1
        room:addPlayerEquipSlots(player, { Player.WeaponSlot })
        if x == 5 then
          break
        end
      end
    room:setPlayerMark(player,"xiuluo__extraslot",x)
    end
    local banner= room:getBanner("@$OutGameWeapons") or {}
    local ingame = getAllCardNames("e")
    local banned = {}
    local bannedCNname = {"弑君","混毒弯匕"}
    for _, card in ipairs(Fk.cards) do
      local name = card.name
      if card and card.type == Card.TypeEquip and card.sub_type == Card.SubtypeWeapon and not table.contains(bannedCNname,Util.TranslateMapper(name)) and not table.contains(banned,name)  then
        --print(Util.TranslateMapper(name))
      if not table.find(ingame, function (ingamename)
        return ingamename == name
      end) then
        if #table.filter(banner,function(cid)
          local card1=Fk:getCardById(cid)
        return card1.name == card.name and card1.suit == card.suit and card1.number == card.number end
        )==0 then
        local c = room:printCard(name, card.suit, card.number)
        table.insertIfNeed(banner, c.id)
        end
      end
    end
    end
    room:setBanner("@$OutGameWeapons", banner)
  end,
  on_lose = function (self, player, is_death)
    local room = player.room
    local x = player:getMark("xiuluo__extraslot")
    if x~=0 then 
    while x >0 do
      x=x-1
      room:removePlayerEquipSlots(player, { Player.WeaponSlot })
      if x == 0 then
        break
      end
    end
  end
  room:setPlayerMark(player,"xiuluo__extraslot",x)
  end,
  refresh_events = {fk.AfterCardsMove,fk.BeforeCardsMove},
  can_refresh = function (self, event, target, player, data)
    return true
  end,
  on_refresh= function (self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
    for _, move in ipairs(data) do
      if move.toArea == Card.Void then
        for _, info in ipairs(move.moveInfo) do
          local card = Fk:getCardById(info.cardId, true)
          if card and card.type == Card.TypeEquip and card.sub_type == Card.SubtypeWeapon then
            local banner = room:getBanner("@$OutGameWeapons")or {}
            table.insertIfNeed(banner,info.cardId)
          room:setBanner("@$OutGameWeapons", banner)
          end
        end
      end
    end
  else
    for _, move in ipairs(data) do
      if move.toArea and move.toArea ~= Card.Void then
        for _, info in ipairs(move.moveInfo) do
          local banner = room:getBanner("@$OutGameWeapons")or {}
          if table.contains(banner,info.cardId) then
          local card = Fk:getCardById(info.cardId, true)
          if card and card.type == Card.TypeEquip and card.sub_type == Card.SubtypeWeapon then
            table.removeOne(banner,info.cardId)
          room:setBanner("@$OutGameWeapons", banner)
          room:setCardMark(card, MarkEnum.DestructOutEquip, 1)
          end
        end
      end
      end
    end
  end
  end,
}
local shenfen = fk.CreateViewAsSkill{
  name = "efengqi__shenfen",
  anim_type = "offensive",
  pattern = "fire__slash",
  card_filter = function(self, to_select, selected)
    local card = Fk:getCardById(to_select)
    return card and card.type == Card.TypeEquip and card.sub_type == Card.SubtypeWeapon
  end,
  view_as = function(self, cards)
    if #cards < 1 then return nil end
    local c = Fk:cloneCard("fire__slash")
    c.skillName = self.name
    c:setMark(self.name, cards)
    return c
  end,
  before_use = function(self, player, use)
    local room = player.room
    if #use.card:getTableMark(self.name)>0 then
      --local banner= room:getBanner("@$OutGameWeapons") or {}
      --table.insertTableIfNeed(banner,use.card:getTableMark(self.name))
      --room:setBanner("@$OutGameWeapons", banner)
    room:moveCardTo(use.card:getTableMark(self.name), Card.Void, nil, fk.ReasonJustMove, self.name, nil, true, player.id)
    end
  end,
  enabled_at_response = function(self, player, response)
    return not response
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
}
local shenfen_target = fk.CreateTargetModSkill {
  name = "#efengqi__shenfen_target",
  extra_target_func = function(self, player, skill, card)
    if card and table.contains(card.skillNames, "efengqi__shenfen") and #card:getTableMark("efengqi__shenfen")>0 then
            return #card:getTableMark("efengqi__shenfen")-1
    end
    return 0
  end,
}
shenfen:addRelatedSkill(shenfen_target)
efengqi__godlvbu:addSkill(xiuluo)
efengqi__godlvbu:addSkill(shenfen)
Fk:loadTranslationTable{
  ['steam_outofgame'] = "一个额外牌堆，由本局游戏开始时牌堆中不包含的武器牌构成（即在牌盒中剩余的武器牌，以及其他额外牌堆中的武器牌）。<br>①当一张武器牌被销毁或移除后，亦或是移动到虚空（或额外牌堆）后，会回到牌盒中的这个牌堆。<br>②离开这个牌堆的牌，会在进入装备区和处理区以外的区域时被销毁，重新洗回牌盒中的这个牌堆。",

  ["efengqi__xiuluo"]="修罗",
  [":efengqi__xiuluo"]="锁定技，你有五个额外的武器栏。准备阶段，若你未装备着<a href=':py_halberd'>【无双方天戟】</a>，你装备之。你造成或受到伤害后，从<a href='steam_outofgame'>游戏外</a>抽一张武器牌并装备。",
  ["efengqi__shenfen"]="神愤",
  [":efengqi__shenfen"]="出牌阶段限一次，你可以销毁任意张武器牌，视为使用一张目标上限相等的火【杀】。",
  ["@$OutGameWeapons"]="游戏外武器牌",
  ["xiuluo__weapon"]="游戏外武器牌",

  ["$efengqi__xiuluo1"]="生我何用，不倒凡力；灭我何用，不减狂傲！",
  ["$efengqi__xiuluo2"]="舍身入魔，佛奈我何？",
  ["$efengqi__xiuluo3"]="修罗之征，岂留活口？",
  ["$efengqi__shenfen1"]="我要神佛烟消云散，我要人间火海滔天！",
  ["$efengqi__shenfen2"]="神罚灭世，炼狱即临！",
  ["~efengqi__godlvbu"] = "神魔之躯，亦难挡刀剑之力……",
}


return extension
